Code for the Airline Management System
Write the object-oriented code to implement the design of the airline management system problem.
We’ve reviewed different aspects of the airline management system and observed the attributes attached to the problem using various UML diagrams. Let’s explore the more practical side of things, where we will work on implementing the airline management system using multiple languages. This is usually the last step in an object-oriented design interview process.
We have chosen the following languages to write the skeleton code of the different classes present in the airline management system:
Java
C#
Python
C++
JavaScript
The airline management system classes#
In this section, we’ll provide the skeleton code of the classes designed in the class diagram lesson.
Note: For simplicity, we are not defining getter and setter functions. The reader can assume that all class attributes are private and accessed through their respective public getter methods and modified only through their public methods function.
Constants#
The following code provides the definition of the various enums and custom data types being used in the airline management system:
Note: JavaScript does not support enumerations, so we will be using the
Object.freeze()
method as an alternative that freezes an object and prevents further modifications.
Account and passenger#
The Account class refers to an account for any user including admin, crew, front desk officer, and a customer. The Passenger class represents the passengers in the airline system. The definition of this class is given below:
Person#
Person
is an abstract class that represents the various people or actors that can interact with the system. There are four types of persons: Admin
, Crew
, FrontDeskOfficer
, and Customer
. The implementation of the mentioned classes is shown below:
Seat and flight seat#
The Seat
and FlightSeat
are used to keep track of the customer’s seat. Here, Seat
is the physical seat in the aircraft and FlightSeat
is the seat assigned to a specific flight instance. The definition of these two classes is given below:
Flight and flight instance#
The Flight
and FlightInstance
classes provide the details of the flight and its instances to the customer. The definition of these classes is given below:
Itinerary and flight reservation#
The Itinerary
and FlightReservation
classes are used to keep track of itineraries and flights reserved by the customers. Both classes are defined below:
Payment#
The Payment
class is another abstract class with two child classes: Cash
and CreditCard
. This takes the PaymentStatus
enum to keep track of the payment status. The definition of this class is provided below:
Notification#
The Notification
class is another abstract class responsible for sending notifications with two child classes: SMSNotification
and EmailNotification
. The implementation of this class is shown below:
Search and catalog#
The SearchCatalog
class contains the flight instance information and implements the Search
interface class to enable the search functionality based on the criteria. Both classes are defined below:
Airport, aircraft, and airline#
This section contains classes like Airport
, Aircraft
, and Airline
that make up the infrastructure of our airline management system. Here, Airline
is a Singleton class. The definition of these classes is given below:
Wrapping up#
We've explored the complete design of the airline management system in this chapter. We've looked at how a basic airline management system can be visualized using various UML diagrams and designed using object-oriented principles and design patterns.
Activity Diagram for the Airline Management System
Getting Ready: The Cricinfo System